﻿<UserControl x:Class="Graphing.View.PointsView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:ViewModel="clr-namespace:Graphing.ViewModel"
             mc:Ignorable="d" MinWidth="770" Height="150" d:DesignHeight="74" d:DesignWidth="659">
    
    <UserControl.Resources>
        <ViewModel:PointsViewModel x:Key="PointsViewModel" />
     
        <!-- Validation Error Template(used to display the error message on the bottom of the boxes) -->   
        <ControlTemplate x:Key="validationTemplate">
            <DockPanel LastChildFill="True">
                <TextBlock DockPanel.Dock="Bottom" 
                            Foreground="Red"
                            FontSize="12"
                            Text="{Binding ElementName=MyAdorner, 
                                    Path=AdornedElement.(Validation.Errors).CurrentItem.ErrorContent}"
                                    >
                </TextBlock>
                <Border BorderBrush="Red" BorderThickness="1" MinWidth="82" MinHeight="25">
                    <AdornedElementPlaceholder Name="MyAdorner" MinWidth="82" MinHeight="25" /> 
                </Border>
            </DockPanel>
        </ControlTemplate>
    </UserControl.Resources>
    
    <Grid DataContext="{StaticResource PointsViewModel}">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="26*" />
            <ColumnDefinition Width="20*" />
            <ColumnDefinition Width="146*" />
            <ColumnDefinition Width="20*" />
            <ColumnDefinition Width="146*" />
            <ColumnDefinition Width="20*" />
            <ColumnDefinition Width="145*" />
            <ColumnDefinition Width="82*" />
        </Grid.ColumnDefinitions>

        <Grid.RowDefinitions>
            <RowDefinition Height="50"/>
            <RowDefinition Height="25" />
            <RowDefinition Height="25" />
            <RowDefinition Height="50" />
        </Grid.RowDefinitions>

        <!-- Point Row. -->
        <!-- Point Label. -->
        <Label Content="Point" Grid.Column="0" Grid.Row="1" MinHeight="25" MinWidth="65" Name="point" Foreground="Black" />

        <!-- X Label. -->
        <Label Content="X:" Grid.Column="1" Grid.Row="1" MinHeight="25" MinWidth="35" Name="x" />

        <!-- X TextBox. -->
        <TextBox Validation.ErrorTemplate="{StaticResource validationTemplate}" Text="{Binding Path=x, ValidatesOnExceptions=True, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}"  
                 Grid.Column="2" Grid.Row="1" MinHeight="25" MinWidth="82" BorderThickness="2" x:Name="xEdit" />

        <!-- Y Label. -->
        <Label Content="Y:" Grid.Column="3" Grid.Row="1" MinHeight="25" MinWidth="35" Name="y" />

        <!-- Y Text Box. -->
        <TextBox Validation.ErrorTemplate="{StaticResource validationTemplate}" Text="{Binding Path=y, ValidatesOnExceptions=True, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}" 
                 Grid.Column="4" Grid.Row="1"  MinHeight="25" MinWidth="82" BorderThickness="2" Name="yEdit" 
                 />

        <!-- Z Label. -->
        <Label Content="Z:" Grid.Column="5" Grid.Row="1" MinHeight="25" MinWidth="35" Name="z" />

        <!-- Z Text Box. -->
        <TextBox Validation.ErrorTemplate="{StaticResource validationTemplate}" Text="{Binding Path=z, ValidatesOnExceptions=True, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}"
                 Grid.Column="6" Grid.Row="1" MinHeight="25" MinWidth="82" BorderThickness="2" Name="zEdit" 
                 />

        <!-- Buttons. -->
        <!-- Add Points Button. -->
        <Button Command="{Binding Path=AddPointCommand}" IsEnabled="{Binding Path=isValid}" Content="Add Point" Grid.Column="3" Grid.Row="3" Grid.ColumnSpan="2" Height="25" Width="75" Name="addPointBtn" />
        
        <!-- Edit Points Button. -->
        <Button Command="{Binding Path=EditPointCommand}" IsEnabled="{Binding Path=isValid}" Content="Edit Point" Grid.Column="5" Grid.Row="3" Grid.ColumnSpan="2" Height="25" Width="75" Name="editPointBtn" />

        <!-- Display List.-->
        <!-- Points Display List. -->
        <ListBox ItemsSource="{Binding Path=PointsList}" DisplayMemberPath="PointsDisplayFormat" Grid.Column="7" Grid.Row="0" Grid.RowSpan="4" MinHeight="25" MinWidth="120" Name="pointsList" />
    </Grid>
</UserControl>
